<?php
error_reporting(E_ALL^E_NOTICE);

$curDir = dirname(__FILE__);
$frameworkPath = $curDir . '/../library/framework/'; 
require_once $frameworkPath . 'CF.php';
require_once $frameworkPath . 'CF/Loader.php';

# disable magic quote gpc
CF::disableMagicQuote();

# add include path to framework
CF_Loader::addIncludePath($frameworkPath);

# register autoload
CF_Loader::registerAutoload();

#application path
$appPath = $curDir . '/../application/';

# database config
$configReader = new CF_Storage_Ini($appPath . 'config/config.ini', 'dev', false);

# create database connection
$connection = new CF_Db_Connection('default', $configReader->database);
CF_Db::getInstance()->addConnection($connection);
CF_Db::getInstance()->traceQueryError = true;

//session_write_close();
$sessionSaveHander = new CF_Session_SaveHandler_Db('sessions');
CF_Session::setSaveHander($sessionSaveHander);
CF_Session::start();

# set application path
CF_App::getInstance()->setPath($appPath);
# set layout
CF_App::getInstance()->getView()->setLayout('default');

$request = new CF_App_Controller_Request('/icafe/public/');
$request->setUrlParamsIndex(
	array(
		'module' => 0,
		'controller' => 1,
		'action' => 2
	)
);
CF_App::getInstance()->getControler()->setRequest($request);
# run application
CF_App::getInstance()->run();
//session_write_close();
